package com.tool.btn;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

import javax.swing.JList;
import javax.swing.SwingConstants;

import org.come.Frame.ApointJframe;
import org.come.Frame.FactionAngelJframe;
import org.come.Frame.FactionAngelPracticeJframe;
import org.come.Frame.OptionsJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.ApointJpanel;
import org.come.Jpanel.FactionAngelJpanel;
import org.come.Jpanel.FactionAngelModelJpanel;
import org.come.Jpanel.FactionAngelPracticeJpanel;
import org.come.Jpanel.FactionDetailsJpanel;
import org.come.Jpanel.FactionMainJpanel;
import org.come.Jpanel.FactionMemberJpanel;
import org.come.Jpanel.FactionPandectJpanel;
import org.come.Jpanel.FactionWarJpanel;
import org.come.bean.LoginResult;
import org.come.entity.Gangapplytable;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.AnalysisString;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;

import com.tool.imagemonitor.PlayerMonitor;
import com.tool.role.RoleData;
import com.updateNew.MyIsif;

import come.tool.JDialog.TiShiUtil;

 

/**
 * 帮派按钮
 * 
 * @author HGC<br>
 * @time 2020年1月11日 上午10:25:40<br>
 * @class 类名:FactionBtn<br>
 */
public class FactionBtn extends MoBanBtn {

    /**
     * 字段名 : caozuo 帮派总览菜单按钮1 帮派成员菜单按钮2 帮派战报菜单按钮3 全部成员菜单按钮5 核心成员菜单按钮6 申请人菜单按钮7
     * 赏功堂8 帮派仓库9 任职10 卸任/拒绝玩家11 逐出/踢出帮派/接收玩家12 脱离帮派/清空列表13 添加朋友14 战报详情15
     * 小成修炼菜单按钮16 大成修炼菜单按钮17 向左减少点数18 向右添加点数19 修炼20 洗点21 兑换22 确认23 大成修炼/小成修炼24 <br>
     */
    private int caozuo;
    private FactionMainJpanel factionMainJpanel;
    private FactionMemberJpanel factionMemberJpanel;
    private FactionPandectJpanel factionPandectJpanel;
    private FactionWarJpanel factionWarJpanel;
    private FactionDetailsJpanel factionDetailsJpanel;
    private FactionAngelJpanel factionAngelJpanel;
    private FactionAngelModelJpanel factionAngelModelJpanel;
    private FactionAngelPracticeJpanel factionAngelPracticeJpanel;

    public FactionBtn(String iconpath, int type, int caozuo, FactionPandectJpanel factionPandectJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.factionPandectJpanel = factionPandectJpanel;
    }

    public FactionBtn(String iconpath, int type, int caozuo, FactionAngelModelJpanel factionAngelModelJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.factionAngelModelJpanel = factionAngelModelJpanel;
    }

    public FactionBtn(String iconpath, int type, int caozuo, FactionMemberJpanel factionMemberJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.factionMemberJpanel = factionMemberJpanel;
    }

    public FactionBtn(String iconpath, int type, int caozuo, FactionAngelJpanel factionAngelJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.factionAngelJpanel = factionAngelJpanel;
    }

    public FactionBtn(String iconpath, int type, int caozuo, FactionMainJpanel factionMainJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.factionMainJpanel = factionMainJpanel;
    }

    public FactionBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
            FactionPandectJpanel factionPandectJpanel) {
        super(iconpath, type, colors);
        setFont(font);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.factionPandectJpanel = factionPandectJpanel;
    }

    public FactionBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
            FactionMemberJpanel factionMemberJpanel) {
        super(iconpath, type, colors);
        setFont(font);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.factionMemberJpanel = factionMemberJpanel;
    }

    public FactionBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
            FactionWarJpanel factionWarJpanel) {
        super(iconpath, type, colors);
        setFont(font);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.factionWarJpanel = factionWarJpanel;
    }

    public FactionBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
            FactionDetailsJpanel factionDetailsJpanel) {
        super(iconpath, type, colors);
        setFont(font);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.factionDetailsJpanel = factionDetailsJpanel;
    }

    public FactionBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
            FactionAngelJpanel factionAngelJpanel) {
        super(iconpath, type, colors);
        setFont(font);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.factionAngelJpanel = factionAngelJpanel;
    }

    public FactionBtn(String iconpath, int type, Color[] colors, String text, Font font, int caozuo,
            FactionAngelPracticeJpanel factionAngelPracticeJpanel) {
        super(iconpath, type, colors);
        setFont(font);
        setText(text);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.caozuo = caozuo;
        this.factionAngelPracticeJpanel = factionAngelPracticeJpanel;
    }







    @Override
    public void chooseyes() {

    }

    @Override
    public void chooseno() {

    }

    @Override
    public void nochoose(MouseEvent e) {
        try {
            if("水墨UI".equals(MyIsif.getStyle())) {
        		if (caozuo == 1) {
                    factionMainJpanel.getBtnMenuPandect().setIcons(CutButtonImage.cuts("skin/8100226/newbutton/K16.png"));
                    factionMainJpanel.getBtnMenuMember().setIcons(CutButtonImage.cuts("skin/8100226/newbutton/K17.png"));
                    factionMainJpanel.getBtnMenuWar().setIcons(CutButtonImage.cuts("skin/8100226/newbutton/K19.png"));
                    factionMainJpanel.getFactionCardJpanel().getCardLayout()
                            .show(factionMainJpanel.getFactionCardJpanel(), "pandect");
                } else if (caozuo == 2) {
                    factionMainJpanel.getBtnMenuPandect().setIcons(CutButtonImage.cuts("skin/8100226/newbutton/K15.png"));
                    factionMainJpanel.getBtnMenuMember().setIcons(CutButtonImage.cuts("skin/8100226/newbutton/K18.png"));
                    factionMainJpanel.getBtnMenuWar().setIcons(CutButtonImage.cuts("skin/8100226/newbutton/K19.png"));
                    factionMainJpanel.getFactionCardJpanel().getCardLayout()
                            .show(factionMainJpanel.getFactionCardJpanel(), "member");

                } else if (caozuo == 3) {
                    ZhuFrame.getZhuJpanel().addPrompt2("暂未开放,敬请期待");
                    return;
//                     factionMainJpanel.getBtnMenuPandect().setIcons(CutButtonImage.cuts(imageMap.getImgMap().get("K15"),"K15"));
//                     factionMainJpanel.getBtnMenuMember().setIcons(CutButtonImage.cuts(imageMap.getImgMap().get("K17"),"K17"));
//                     factionMainJpanel.getBtnMenuWar().setIcons(CutButtonImage.cuts(imageMap.getImgMap().get("K20"),"K20"));
//                     factionMainJpanel.getFactionCardJpanel().getCardLayout()
//                     .show(factionMainJpanel.getFactionCardJpanel(), "war");
                } else if (caozuo >= 5 && caozuo <= 7) {
                    int menuType = factionMemberJpanel.getMenuType();
                    if (menuType == 5) {
                        factionMemberJpanel.getBtnMenuAll().setIcons(CutButtonImage.cuts("skin/8100226/button/B272.png"));
                    } else if (menuType == 6) {
                        factionMemberJpanel.getBtnMenuCore().setIcons(CutButtonImage.cuts("skin/8100226/button/B274.png"));
                    } else if (menuType == 7) {
                        factionMemberJpanel.getBtnMenuApply().setIcons(CutButtonImage.cuts("skin/8100226/button/B278.png"));
                    }
                    factionMemberJpanel.showBtn(false);
                    factionMemberJpanel.setMenuType(caozuo);
                    menuType = factionMemberJpanel.getMenuType();
                    if (menuType == 5) {
                        factionMemberJpanel.getBtnMenuAll().setIcons(CutButtonImage.cuts("skin/8100226/button/B273.png"));
                        factionMemberJpanel.setIconCoumn(null);
                    } else if (menuType == 6) {
                        factionMemberJpanel.getBtnMenuCore().setIcons(CutButtonImage.cuts("skin/8100226/button/B275.png"));
                        factionMemberJpanel.setIconCoumn(null);
                    } else if (menuType == 7) {
                        factionMemberJpanel.getBtnMenuApply().setIcons(CutButtonImage.cuts("skin/8100226/button/B279.png"));
                        factionMemberJpanel.setIconCoumn(CutButtonImage.getImage("inkImg/old/background/S170.png", -1, -1));
                    }
                    factionMemberJpanel.showBtn(true);
                    factionMemberJpanel.changeTable();
                    factionMemberJpanel.showMenuMessage(factionMemberJpanel.getFactionCardJpanel().getGangResultBean());
                } else if (caozuo == 10) {// 任命
                    Abdicate();
                } else if (caozuo == 11) {// 卸任/拒绝玩家
                    if ("卸任".equals(getText())) {
                        Appointment();
                    } else if ("拒绝玩家".equals(getText())) {
                        RefuseJoin();
                    }
                } else if (caozuo == 12) {// 逐出/踢出帮派/接收玩家
                    if ("踢出帮派".equals(getText())) {
                        Kickout();
                    } else if ("逐出".equals(getText())) {

                    } else if ("接收玩家".equals(getText())) {
                        AgreeJoin();
                    }
                } else if (caozuo == 13) {// 脱离帮派/清空列表
                    if ("脱离帮派".equals(getText())) {
                        BreakAway();
                    } else if ("清空列表".equals(getText())) {
                        clearApply();
                    }
                } else if (caozuo == 14) {// 添加好友
                    if (factionMemberJpanel.getMenuType() != 7) {
                        int selectedRow = factionMemberJpanel.getTable().getSelectedRow();
                        if (selectedRow != -1) {
                            LoginResult loginResult = factionMemberJpanel.getFactionCardJpanel().getGangResultBean()
                                    .getRoleTables().get(selectedRow);
                            PlayerMonitor.addFriend(loginResult.getRole_id(), loginResult.getRolename());
                        }
                    } else {
                        int selectedRow = factionMemberJpanel.getTable().getSelectedRow();
                        if (selectedRow != -1) {
                            Gangapplytable gangapplytable = factionMemberJpanel.getFactionCardJpanel().getGangResultBean()
                                    .getGangapplytables().get(selectedRow);
                            PlayerMonitor.addFriend(gangapplytable.getRole_id(), gangapplytable.getRolename());
                        }
                    }
                } else if (caozuo == 15) {
                    FormsManagement.showForm(49);
                } else if (caozuo == 25) {
        			FormsManagement.showForm(112);
        		} else if (caozuo == 16) {
                    factionAngelJpanel.changeMenuShow(1);
                } else if (caozuo == 17) {
                    factionAngelJpanel.changeMenuShow(2);
                } else if (caozuo == 18) {
                    FactionAngelJpanel angelJpanel = FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel();
                    // if (angelJpanel.getTypeLvlResidue() <= 0) {
                    // ZhuFrame.getZhuJpanel().addPrompt2("剩余点数不足");
                    // return;
                    // }
                    if (factionAngelModelJpanel.getLvlChange() <= factionAngelModelJpanel.getLvlNow()) {
                        ZhuFrame.getZhuJpanel().addPrompt2("不可以再减少点数了");
                        return;
                    } else {
                        factionAngelModelJpanel.setLvlChange(factionAngelModelJpanel.getLvlChange() - 1);
                        factionAngelModelJpanel.refreshLvlChange();
                        angelJpanel.setTypeLvlResidue(angelJpanel.getTypeLvlResidue() + 1);
                        if (factionAngelModelJpanel.getLvlChange() <= factionAngelModelJpanel.getLvlNow()) {
                            factionAngelModelJpanel.getLabDegree().setForeground(Color.white);
                            factionAngelModelJpanel.getLabLvl().setForeground(Color.WHITE);
                        }
                    }

                } else if (caozuo == 19) {
                    FactionAngelJpanel angelJpanel = FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel();
                    if (angelJpanel.getTypeLvlResidue() <= 0) {
                        ZhuFrame.getZhuJpanel().addPrompt2("剩余点数不足");
                        return;
                    }
                    int typeNumMax = 20;
                    int menuType = angelJpanel.getMenuType();
                    if (menuType == 1) {
                        typeNumMax = 20;
                    } else if (menuType == 2) {
                        typeNumMax = 30;
                    }
                    if (factionAngelModelJpanel.getLvlChange() >= typeNumMax) {
                        ZhuFrame.getZhuJpanel().addPrompt2("不可以再增加点数了");
                        return;
                    } else {
                        factionAngelModelJpanel.setLvlChange(factionAngelModelJpanel.getLvlChange() + 1);
                        factionAngelModelJpanel.refreshLvlChange();
                        angelJpanel.setTypeLvlResidue(angelJpanel.getTypeLvlResidue() - 1);
                        if (factionAngelModelJpanel.getLvlChange() > factionAngelModelJpanel.getLvlNow()) {
                            factionAngelModelJpanel.getLabDegree().setForeground(Color.GREEN);
                            factionAngelModelJpanel.getLabLvl().setForeground(Color.GREEN);
                        }
                    }
                } else if (caozuo == 20) {
                    FormsManagement.showForm(106);
                    FactionAngelPracticeJframe.getFactionAngelPracticeJframe().getFactionAngelPracticeJpanel()
                            .showPanel(factionAngelJpanel.getMenuType());
                } else if (caozuo == 21) {
                	String[] resistance = RoleData.getRoleData().getLoginResult().getResistance(factionAngelJpanel.getMenuType()==1?"X":"D");
                	if (resistance==null) {
                		ZhuFrame.getZhuJpanel().addPrompt2("你还没加点怎么洗点");
                        return;
    				}
                	OptionsJframe.getOptionsJframe().getOptionsJpanel().
    				showBox(TiShiUtil.washPoint, 7+(factionAngelJpanel.getMenuType()==1?"X":"D"),"#W确定要花50W银两重置#G"+(factionAngelJpanel.getMenuType()==1?"小成修炼":"大成修炼")+"?");  
    			} else if (caozuo == 23) {
                	JList<FactionAngelModelJpanel> list=factionAngelJpanel.getListFactionJpanel();
                	StringBuffer buffer=new StringBuffer();
                	buffer.append(7);
                	buffer.append(factionAngelJpanel.getMenuType()==1?"X":"D");
                	boolean is=true;
                	for (int i = 0, length=factionAngelJpanel.getMenuType()==1?13:18; i < length; i++) {
                		FactionAngelModelJpanel jpanel=(FactionAngelModelJpanel) list.getComponent(i);
                		if (jpanel.getLvlChange()==0) {continue;}
                		if (jpanel.getLvlNow()!=jpanel.getLvlChange()) {is=false;}
                		if (buffer.length()>2) {buffer.append("#");}
                		buffer.append(jpanel.getLabName().getText());
                		buffer.append("=");
                		buffer.append(jpanel.getLvlValue());
                	}
                	if (is) {
                		ZhuFrame.getZhuJpanel().addPrompt2("你还未修改");
                        return;
    				}
                	String mes = Agreement.getAgreement().rolechangeAgreement(buffer.toString());
                    SendMessageUntil.toServer(mes);
                } else if (caozuo == 24) {// 大成修炼/小成修炼
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    if ("大成修炼".equals(getText())) {
                        int extraPointInt = loginResult.getExtraPointInt("X");
                        if (extraPointInt < 30) {
                            ZhuFrame.getZhuJpanel().addPrompt2("小成修炼尚未结束");
                            return;
                        }
                        int pointInt = loginResult.getExtraPointInt("D");
                        if (pointInt >= 60) {
                            ZhuFrame.getZhuJpanel().addPrompt2("大成修炼已经结束");
                            return;
                        }
                        if (loginResult.getExperience().compareTo(new BigDecimal(5000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("经验不足");
                            return;
                        }
                        if (loginResult.getContribution().compareTo(new BigDecimal(1500)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("帮贡不足");
                            return;
                        }
                        if (loginResult.getGold().compareTo(new BigDecimal(5000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("金钱不足");
                            return;
                        }
                        String mes = Agreement.getAgreement().rolechangeAgreement("6D");
                        SendMessageUntil.toServer(mes);
                    } else if ("小成修炼".equals(getText())) {
                        int extraPointInt = loginResult.getExtraPointInt("X");
                        if (extraPointInt >= 30) {
                            ZhuFrame.getZhuJpanel().addPrompt2("小成修炼已经修炼完毕");
                            return;
                        }
                        if (loginResult.getExperience().compareTo(new BigDecimal(2000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("经验不足");
                            return;
                        }
                        if (loginResult.getContribution().compareTo(new BigDecimal(300)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("帮贡不足");
                            return;
                        }
                        if (loginResult.getGold().compareTo(new BigDecimal(2000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("金钱不足");
                            return;
                        }
                        String mes = Agreement.getAgreement().rolechangeAgreement("6X");
                        SendMessageUntil.toServer(mes);
                    }
                }


            }else{
                if (caozuo == 1) {
                    factionMainJpanel.getBtnMenuPandect().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B270.png"));
                    factionMainJpanel.getBtnMenuMember().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B267.png"));
                    factionMainJpanel.getBtnMenuWar().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B269.png"));
                    factionMainJpanel.getFactionCardJpanel().getCardLayout()
                            .show(factionMainJpanel.getFactionCardJpanel(), "pandect");
                } else if (caozuo == 2) {
                    factionMainJpanel.getBtnMenuPandect().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B271.png"));
                    factionMainJpanel.getBtnMenuMember().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B266.png"));
                    factionMainJpanel.getBtnMenuWar().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B269.png"));
                    factionMainJpanel.getFactionCardJpanel().getCardLayout()
                            .show(factionMainJpanel.getFactionCardJpanel(), "member");

                } else if (caozuo == 3) {
                    ZhuFrame.getZhuJpanel().addPrompt2("暂未开放,敬请期待");
                    return;
                    //factionMainJpanel.getBtnMenuPandect().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B271.png"));
                    // factionMainJpanel.getBtnMenuMember().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B267.png"));
                    // factionMainJpanel.getBtnMenuWar().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B268.png"));
                    // factionMainJpanel.getFactionCardJpanel().getCardLayout()
                    // .show(factionMainJpanel.getFactionCardJpanel(), "war");
                } else if (caozuo >= 5 && caozuo <= 7) {
                    int menuType = factionMemberJpanel.getMenuType();
                    if (menuType == 5) {
                        factionMemberJpanel.getBtnMenuAll().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B272.png"));
                    } else if (menuType == 6) {
                        factionMemberJpanel.getBtnMenuCore().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B274.png"));
                    } else if (menuType == 7) {
                        factionMemberJpanel.getBtnMenuApply().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/V291.png"));
                    }
                    factionMemberJpanel.showBtn(false);
                    factionMemberJpanel.setMenuType(caozuo);
                    menuType = factionMemberJpanel.getMenuType();
                    if (menuType == 5) {
                        factionMemberJpanel.getBtnMenuAll().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B273.png"));
                        factionMemberJpanel.setIconCoumn(null);
                    } else if (menuType == 6) {
                        factionMemberJpanel.getBtnMenuCore().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/B275.png"));
                        factionMemberJpanel.setIconCoumn(null);
                    } else if (menuType == 7) {
                        factionMemberJpanel.getBtnMenuApply().setIcons(CutButtonImage.cuts("inkImg/hongmu/2/V290.png"));
                        factionMemberJpanel.setIconCoumn(CutButtonImage.getImage("inkImg/hongmu/2/S170.png", -1, -1));
                    }
                    factionMemberJpanel.showBtn(true);
                    factionMemberJpanel.changeTable();
                    factionMemberJpanel.showMenuMessage(factionMemberJpanel.getFactionCardJpanel().getGangResultBean());
                } else if (caozuo == 10) {// 任命
                    Abdicate();
                } else if (caozuo == 11) {// 卸任/拒绝玩家
                    if ("卸任".equals(getText())) {
                        Appointment();
                    } else if ("拒绝玩家".equals(getText())) {
                        RefuseJoin();
                    }
                } else if (caozuo == 12) {// 逐出/踢出帮派/接收玩家
                    if ("踢出帮派".equals(getText())) {
                        Kickout();
                    } else if ("逐出".equals(getText())) {

                    } else if ("接收玩家".equals(getText())) {
                        AgreeJoin();
                    }
                } else if (caozuo == 13) {// 脱离帮派/清空列表
                    if ("脱离帮派".equals(getText())) {
                        BreakAway();
                    } else if ("清空列表".equals(getText())) {
                        clearApply();
                    }
                } else if (caozuo == 14) {// 添加好友
                    if (factionMemberJpanel.getMenuType() != 7) {
                        int selectedRow = factionMemberJpanel.getTable().getSelectedRow();
                        if (selectedRow != -1) {
                            LoginResult loginResult = factionMemberJpanel.getFactionCardJpanel().getGangResultBean()
                                    .getRoleTables().get(selectedRow);
                            PlayerMonitor.addFriend(loginResult.getRole_id(), loginResult.getRolename());
                        }
                    } else {
                        int selectedRow = factionMemberJpanel.getTable().getSelectedRow();
                        if (selectedRow != -1) {
                            Gangapplytable gangapplytable = factionMemberJpanel.getFactionCardJpanel().getGangResultBean()
                                    .getGangapplytables().get(selectedRow);
                            PlayerMonitor.addFriend(gangapplytable.getRole_id(), gangapplytable.getRolename());
                        }
                    }
                } else if (caozuo == 15) {
                    FormsManagement.showForm(49);
                } else if (caozuo == 25) {
                    FormsManagement.showForm(112);
                } else if (caozuo == 16) {
                    factionAngelJpanel.changeMenuShow(1);
                } else if (caozuo == 17) {
                    factionAngelJpanel.changeMenuShow(2);
                } else if (caozuo == 18) {
                    FactionAngelJpanel angelJpanel = FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel();
                    // if (angelJpanel.getTypeLvlResidue() <= 0) {
                    // ZhuFrame.getZhuJpanel().addPrompt2("剩余点数不足");
                    // return;
                    // }
                    if (factionAngelModelJpanel.getLvlChange() <= factionAngelModelJpanel.getLvlNow()) {
                        ZhuFrame.getZhuJpanel().addPrompt2("不可以再减少点数了");
                        return;
                    } else {
                        factionAngelModelJpanel.setLvlChange(factionAngelModelJpanel.getLvlChange() - 1);
                        factionAngelModelJpanel.refreshLvlChange();
                        angelJpanel.setTypeLvlResidue(angelJpanel.getTypeLvlResidue() + 1);
                        if (factionAngelModelJpanel.getLvlChange() <= factionAngelModelJpanel.getLvlNow()) {
                            factionAngelModelJpanel.getLabDegree().setForeground(Color.white);
                            factionAngelModelJpanel.getLabLvl().setForeground(Color.WHITE);
                        }
                    }

                } else if (caozuo == 19) {
                    FactionAngelJpanel angelJpanel = FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel();
                    if (angelJpanel.getTypeLvlResidue() <= 0) {
                        ZhuFrame.getZhuJpanel().addPrompt2("剩余点数不足");
                        return;
                    }
                    int typeNumMax = 20;
                    int menuType = angelJpanel.getMenuType();
                    if (menuType == 1) {
                        typeNumMax = 20;
                    } else if (menuType == 2) {
                        typeNumMax = 30;
                    }
                    if (factionAngelModelJpanel.getLvlChange() >= typeNumMax) {
                        ZhuFrame.getZhuJpanel().addPrompt2("不可以再增加点数了");
                        return;
                    } else {
                        factionAngelModelJpanel.setLvlChange(factionAngelModelJpanel.getLvlChange() + 1);
                        factionAngelModelJpanel.refreshLvlChange();
                        angelJpanel.setTypeLvlResidue(angelJpanel.getTypeLvlResidue() - 1);
                        if (factionAngelModelJpanel.getLvlChange() > factionAngelModelJpanel.getLvlNow()) {
                            factionAngelModelJpanel.getLabDegree().setForeground(Color.GREEN);
                            factionAngelModelJpanel.getLabLvl().setForeground(Color.GREEN);
                        }
                    }
                } else if (caozuo == 20) {
                    FormsManagement.showForm(106);
                    FactionAngelPracticeJframe.getFactionAngelPracticeJframe().getFactionAngelPracticeJpanel()
                            .showPanel(factionAngelJpanel.getMenuType());
                } else if (caozuo == 21) {
                    String[] resistance = RoleData.getRoleData().getLoginResult().getResistance(factionAngelJpanel.getMenuType()==1?"X":"D");
                    if (resistance==null) {
                        ZhuFrame.getZhuJpanel().addPrompt2("你还没加点怎么洗点");
                        return;
                    }
                    OptionsJframe.getOptionsJframe().getOptionsJpanel().
                            showBox(TiShiUtil.washPoint, 7+(factionAngelJpanel.getMenuType()==1?"X":"D"),"#W确定要花50W银两重置#G"+(factionAngelJpanel.getMenuType()==1?"小成修炼":"大成修炼")+"?");
                } else if (caozuo == 23) {
                    JList<FactionAngelModelJpanel> list=factionAngelJpanel.getListFactionJpanel();
                    StringBuffer buffer=new StringBuffer();
                    buffer.append(7);
                    buffer.append(factionAngelJpanel.getMenuType()==1?"X":"D");
                    boolean is=true;
                    for (int i = 0, length=factionAngelJpanel.getMenuType()==1?13:18; i < length; i++) {
                        FactionAngelModelJpanel jpanel=(FactionAngelModelJpanel) list.getComponent(i);
                        if (jpanel.getLvlChange()==0) {continue;}
                        if (jpanel.getLvlNow()!=jpanel.getLvlChange()) {is=false;}
                        if (buffer.length()>2) {buffer.append("#");}
                        buffer.append(jpanel.getLabName().getText());
                        buffer.append("=");
                        buffer.append(jpanel.getLvlValue());
                    }
                    if (is) {
                        ZhuFrame.getZhuJpanel().addPrompt2("你还未修改");
                        return;
                    }
                    String mes = Agreement.getAgreement().rolechangeAgreement(buffer.toString());
                    SendMessageUntil.toServer(mes);
                } else if (caozuo == 24) {// 大成修炼/小成修炼
                    LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                    if ("大成修炼".equals(getText())) {
                        int extraPointInt = loginResult.getExtraPointInt("X");
                        if (extraPointInt < 30) {
                            ZhuFrame.getZhuJpanel().addPrompt2("小成修炼尚未结束");
                            return;
                        }
                        int pointInt = loginResult.getExtraPointInt("D");
                        if (pointInt >= 60) {
                            ZhuFrame.getZhuJpanel().addPrompt2("大成修炼已经结束");
                            return;
                        }
                        if (loginResult.getExperience().compareTo(new BigDecimal(5000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("经验不足");
                            return;
                        }
                        if (loginResult.getContribution().compareTo(new BigDecimal(1500)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("帮贡不足");
                            return;
                        }
                        if (loginResult.getGold().compareTo(new BigDecimal(5000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("金钱不足");
                            return;
                        }
                        String mes = Agreement.getAgreement().rolechangeAgreement("6D");
                        SendMessageUntil.toServer(mes);
                    } else if ("小成修炼".equals(getText())) {
                        int extraPointInt = loginResult.getExtraPointInt("X");
                        if (extraPointInt >= 30) {
                            ZhuFrame.getZhuJpanel().addPrompt2("小成修炼已经修炼完毕");
                            return;
                        }
                        if (loginResult.getExperience().compareTo(new BigDecimal(2000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("经验不足");
                            return;
                        }
                        if (loginResult.getContribution().compareTo(new BigDecimal(300)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("帮贡不足");
                            return;
                        }
                        if (loginResult.getGold().compareTo(new BigDecimal(2000000)) < 0) {
                            ZhuFrame.getZhuJpanel().addPrompt2("金钱不足");
                            return;
                        }
                        String mes = Agreement.getAgreement().rolechangeAgreement("6X");
                        SendMessageUntil.toServer(mes);
                    }
                }
            }

        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
    
    /** 脱离帮派 */
    public void BreakAway() {
        if (!"帮主".equals(RoleData.getRoleData().getLoginResult().getGangpost())) {
            OptionsJframe.getOptionsJframe().getOptionsJpanel()
                    .showBox(TiShiUtil.BreakAway, "消息", "#Y       您确定要脱离帮派吗?");
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("帮主不能退出帮派!");
        }
    }

    /** 踢出帮派 */
    public void Kickout() {
        if ("帮主".equals(RoleData.getRoleData().getLoginResult().getGangpost())) {
            int index = -1;
            // index值，这些index值由一个int array返回.
            LoginResult roleTable = null;
            index = factionMemberJpanel.getTable().getSelectedRow();
            if (index == -1) {
                ZhuFrame.getZhuJpanel().addPrompt2("请选择一个帮派人员！");
                return;
            }
            roleTable = factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getRoleTables().get(index);
            String tiren = "";
            if (roleTable != null
                    && !roleTable.getRolename().equals(RoleData.getRoleData().getLoginResult().getRolename())) {
                tiren = roleTable.getRolename();
            }
            if (tiren != null && !"".equals(tiren)) {
                OptionsJframe.getOptionsJframe().getOptionsJpanel()
                        .showBox(TiShiUtil.KickOut, index, "#Y  您确定要将  #G" + tiren + "    #Y踢出帮派吗?");
            } else {
                ZhuFrame.getZhuJpanel().addPrompt2("不能踢你自己!");
            }
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("只有帮主才有权利踢人!");
        }
    }

    /** 允许加入帮派 */
    public void AgreeJoin() {
        if (factionMemberJpanel.Important(RoleData.getRoleData().getLoginResult().getGangpost())) {
            int index = factionMemberJpanel.getTable().getSelectedRow();
            if (index == -1) {
                ZhuFrame.getZhuJpanel().addPrompt2("请选择一个帮派人员！");
                return;
            }
            tongyi(index);
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("只有护法以上才有权利操作!");
        }
    }

    /**
     * 允许申请加入
     */
    public void tongyi(int index) {
        try {
            // 复制写给客户端的流
            String sendMes = Agreement.GangAgreeAgreement(factionMemberJpanel.getFactionCardJpanel()
                    .getGangResultBean().getGangapplytables().get(index).getRole_id().toString());
            // 向服务器发送信息
            SendMessageUntil.toServer(sendMes);
            factionMemberJpanel.getTableModel().removeRow(index);
            factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getGangapplytables().remove(index);
        } catch (Exception e2) {
        }
    }

    /** 拒绝加入帮派 */
    public void RefuseJoin() {
        if ("帮主".equals(RoleData.getRoleData().getLoginResult().getGangpost())
                || "护法".equals(RoleData.getRoleData().getLoginResult().getGangpost())) {
            int index = factionMemberJpanel.getTable().getSelectedRow();
            if (index == -1) {
                ZhuFrame.getZhuJpanel().addPrompt2("请选择一个帮派人员！");
                return;
            }
            jujue(index);
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("只有护法以上才有权利操作!");
        }
    }

    /**
     * 拒绝申请加入
     */
    public void jujue(int index) {

        try {
            // 复制写给客户端的流

            String sendMes = Agreement.GangRefuseAgreement(factionMemberJpanel.getFactionCardJpanel()
                    .getGangResultBean().getGangapplytables().get(index).getRole_id().toString());
            // 向服务器发送信息
            SendMessageUntil.toServer(sendMes);
            factionMemberJpanel.getTableModel().removeRow(index);
            factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getGangapplytables().remove(index);
        } catch (Exception e2) {
        }
    }

    /** 职务任命 */
    public void Abdicate() {
        if ("帮主".equals(RoleData.getRoleData().getLoginResult().getGangpost())) {
            if (xuanzhong()) {
                FormsManagement.showForm(37);
            }
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("只有帮主才有权利!");
        }
    }

    /** 选中 */
    public boolean xuanzhong() {
        try {
            int index = factionMemberJpanel.getTable().getSelectedRow();
            if (index == -1) {
                ZhuFrame.getZhuJpanel().addPrompt2("请选择一个帮派人员！");
                return false;
            }
            if (factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getRoleTables().get(index).getRole_id()
                    .compareTo(RoleData.getRoleData().getLoginResult().getRole_id()) != 0) {
                ApointJpanel apointJpanel = ApointJframe.getApointJframe().getApointJpanel();
                apointJpanel.getLabname().setText(
                        factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getRoleTables().get(index)
                                .getRolename());
                apointJpanel.getLabRace().setText(
                        factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getRoleTables().get(index)
                                .getRace_name());
                apointJpanel.getLabLevel().setText(
                        AnalysisString.lvl(factionMemberJpanel.getFactionCardJpanel().getGangResultBean()
                                .getRoleTables().get(index).getGrade()));
                ApointJpanel.index = index;
                return true;
            } else {
                ZhuFrame.getZhuJpanel().addPrompt2("不能对自己进行操作!");
            }
        } catch (Exception e2) {

        }
        return false;
    }

    /** 退位让贤 */
    public void Appointment() {
        if ("帮主".equals(RoleData.getRoleData().getLoginResult().getGangpost())) {
            int index = -1;
            // index值，这些index值由一个int array返回.
            LoginResult roleTable = null;
            try {
                index = factionMemberJpanel.getTable().getSelectedRow();
                if (index == -1) {
                    ZhuFrame.getZhuJpanel().addPrompt2("请选择一个帮派人员！");
                    return;
                }
                roleTable = factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getRoleTables().get(index);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            String tiren = "";
            if (roleTable != null
                    && !roleTable.getRolename().equals(RoleData.getRoleData().getLoginResult().getRolename())) {
                tiren = roleTable.getRolename();
            }
            if (tiren != null && !"".equals(tiren)) {
                OptionsJframe.getOptionsJframe().getOptionsJpanel()
                        .showBox(TiShiUtil.Abdication, index, "#Y  您确定要退位给  #G" + tiren + "    #Y吗?");
            } else {
                ZhuFrame.getZhuJpanel().addPrompt2("不能退位给你自己!");
            }
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("你不是帮主吧!");
        }
    }

    /** 清空申请人列表 */
    public void clearApply() {
        if (factionMemberJpanel.Important(RoleData.getRoleData().getLoginResult().getGangpost())) {
            // 复制写给客户端的流
            String sendMes = Agreement.GangRefuseAgreement("");
            // 向服务器发送信息
            SendMessageUntil.toServer(sendMes);
            factionMemberJpanel.getTableModel().setRowCount(0);
            factionMemberJpanel.getFactionCardJpanel().getGangResultBean().getGangapplytables().clear();
        } else {
            ZhuFrame.getZhuJpanel().addPrompt2("你不是帮主或者护法");
        }
    }
}
